package com.zzyl.nursing.controller.member;

import cn.hutool.json.ObjectMapper;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;


import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.dto.DeviceByDayDto;
import com.zzyl.nursing.dto.DeviceByWeekDto;
import com.zzyl.nursing.dto.ElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IDeviceDataService;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.service.IFamilyMemberService;

import com.zzyl.nursing.vo.FamilyMemberElderVo;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 *
 * @author ruoyi
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
@Slf4j
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;
    @Autowired
    private IDeviceService  deviceService;
    @Autowired
    private IDeviceDataService deviceDataService;

    @PostMapping("/login")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo vo = familyMemberService.login(dto);
        return success(vo);
    }

    /**
     * 绑定老人
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ElderDto dto ){
        return toAjax(familyMemberService.add(dto));
    }

    /**
     * 查询绑定老人
     * @return
     */
    @GetMapping("/my")
    public AjaxResult my(){
        return success(familyMemberService.selectElderList());
    }
    /**
     * 分页查询绑定老人
     * @param
     * @return
     */
    /*@GetMapping("/list-by-page")
    public TableDataInfo listByPage(FamilyMemberElderVo familyMemberElderVo){
        startPage();
        List<FamilyMemberElderVo> list=familyMemberService.selectElderListByPage(familyMemberElderVo);
        return getDataTable(list);
    }*/
    @GetMapping("/list-by-page")
    public AjaxResult listByPage(){
        startPage();
        List<FamilyMemberElderVo> list=familyMemberService.selectElderListByPage();
        return success(list);
    }
    @GetMapping("/queryServiceProperties/{iotId}")
    public AjaxResult queryServiceProperties(@PathVariable String iotId){
//        return deviceService.queryServiceProperties(iotId);
        return familyMemberService.queryServiceProperties(iotId);
    }
    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(DeviceByDayDto dto){
        AjaxResult ajaxResult = deviceDataService.queryDeviceDataListByDay(dto);
        return ajaxResult;
    }
    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(DeviceByWeekDto dto){
        AjaxResult ajaxResult = deviceDataService.queryDeviceDataListByWeek(dto);
        return ajaxResult;
    }
}

